#include<bits/stdc++.h>
using namespace std;
const int N=400099;
typedef long long ll;
typedef unsigned long long ull;
mt19937 ran(1894651);
int n;
ll x;
unordered_map<ll,bool> vis;
#define pi pair<int,int>
#define mp(x,y) make_pair(x,y)
#define ln son[node][0]
#define rn son[node][1]
int rt,cntnode;
int son[N][2],rd[N],sz[N];
ull val[N],sum1[N],sum2[N];
void pushup(int node){
	sz[node]=sz[ln]+sz[rn]+1;
	sum1[node]=sum1[ln]+sum1[rn]+val[node];
	sum2[node]=sum2[ln]+val[node]*(sz[ln]+1)+sum1[rn]*(sz[ln]+1)+sum2[rn];
	return;
}
pi split(int node,ull x){ //<=x
	if(!node) return mp(0,0);
	if(val[node]<=x){
		pi re=split(rn,x);
		rn=re.first; re.first=node;
		pushup(node);
		return re;
	}
	else{
		pi re=split(ln,x);
		ln=re.second; re.second=node;
		pushup(node);
		return re;
	}
}
int merge(int x,int y){
	if(!x||!y) return x+y;
	if(rd[x]<rd[y]){
		son[x][1]=merge(son[x][1],y);
		pushup(x);
		return x;
	}
	else{
		son[y][0]=merge(x,son[y][0]);
		pushup(y);
		return y;
	}
}
void ins(ll x){
	++cntnode; rd[cntnode]=ran(); sz[cntnode]=1;
	val[cntnode]=sum1[cntnode]=sum2[cntnode]=x;
	pi r=split(rt,x);
	rt=merge(merge(r.first,cntnode),r.second);
	return;
}
void era(ll x){
	pi r=split(rt,x);
	pi rl=split(r.first,x-1);
	rt=merge(rl.first,r.second);
	return;
}
ull sum1_pre(int x){
	int node=rt;
	ull re=0;
	while(node){
		if(sz[ln]>=x) node=ln;
		else{
			re+=sum1[ln]+val[node];
			x-=sz[ln]+1;
			if(!x) return re;
			node=rn;
		}
	}
	return re;
}
ull sum1_bac(int x){
	return sum1[rt]-sum1_pre(n-x);
}
ull sum2_pre(int x){
	int node=rt;
	ull re=0,ad=0;
	while(node){
		if(sz[ln]>=x) node=ln;
		else{
			re+=sum2[ln]+sum1[ln]*ad;
			ad+=sz[ln];
			re+=val[node]*(ad+1);
			ad++; x-=sz[ln]+1;
			if(!x) return re;
			node=rn;
		}
	}
	return re;
}
ull sum2_bac(int x){
	return sum2[rt]-sum2_pre(n-x);
}
void calc(){
	ull ans=sum2[rt]-(sum1[rt]*(n+1)-sum2[rt]);
	if(n&1){
		if(sum1_pre(n/2+1)*2>=sum1[rt]){
			cout<<ans<<'\n';
			return;
		}
	}
	else{
		if(sum1_pre(n/2)>=sum1_bac(n/2-1)){
			cout<<ans<<'\n';
			return;
		}
	}
	int l=1,r=(n-1)/2,mid,re=0;
	while(l<=r){
		mid=(l+r)/2;
		if(sum1_pre(mid+1)>=sum1_bac(mid)) re=mid,l=mid+1;
		else r=mid-1;
	}
	cerr<<re<<endl;
	ans=sum1_bac(n-re-1)-sum1_pre(re+1);
	ans+=(sum1_bac(re)*(n+re)-sum2_bac(re)-sum2_pre(re))*2;
	cerr<<sum2_bac(re)<<endl;
	cerr<<sum2_pre(re)<<endl;
	cout<<ans<<'\n';
	return;
}
char ch;
ll re;
ll read(){
	char ch=getchar(); re=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re;
}
void solve(){
	x=read(); vis[x]^=1;
	if(vis[x]) ins(x),n++;
	else era(x),n--;
	calc();
	return;
}
int main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	int T; T=read();
	while(T--) solve();
	return 0;
}